package com.example.s10_redis_session.service.impl;

import com.example.s10_redis_session.pojo.User;
import com.example.s10_redis_session.service.IUserService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements IUserService
{

    List<User> users = new ArrayList<>();
    long count=2;

    {
        users.add(new User(1L,"zhangsan","123456","zhangsan@qq.com"));
        users.add(new User(2L,"lisi","123456","lisi@qq.com"));
    }

    @Override
    public boolean register(User user)
    {
        count++;
        user.setId(count);
        users.add(user);
        return true;
    }

    @Override
    public User loginchk(String username, String password)
    {
        for(int i=0;i< users.size();i++)
        {
            User u = users.get(i);
            if(u.getUsername().equals(username)&&u.getPassword().equals(password))
            {
                return u;
            }
        }
        return null;
    }
}